package com.zhang.gmallpublishertest.controller;

import com.alibaba.fastjson.JSON;
import com.zhang.gmallpublishertest.service.SugarService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

/**
 * @title:
 * @author: zhang
 * @date: 2022/1/10 20:48
 */
@RestController
@RequestMapping("/api/sugar")
public class SugarController {

    @Autowired
    private SugarService provinceStatsService;


    @RequestMapping("/gmv")
    public String getGMV(@RequestParam(value = "date", defaultValue = "0") Integer date) {
        if (date == 0) {
            date = now();
        }


        HashMap<String, Object> result = new HashMap<>();
        result.put("status", 0);
        result.put("msg", "");
        result.put("data", provinceStatsService.getGmv(date));
        return JSON.toJSONString(result);
    }

    @RequestMapping("/cao")
    public String getCao(){
        return "<h1>cao Apache     cao Apache</h1>";
    }

    private Integer now() {
        String yyyyMMdd = DateFormatUtils.format(new Date(), "yyyyMMdd");
        return Integer.valueOf(yyyyMMdd);
    }
}
